import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get_it/get_it.dart';
import 'package:provider/provider.dart';

import '../../../config/route/bt_app_router.dart';
import '../../../config/route/bt_app_router.gr.dart';
import '../../utils/bt_app_bar_utils.dart';
import '../../utils/bt_dialog_utils.dart';
import '../models/bt_account_setting_model.dart';

@RoutePage(name: "accountSettingRoute")
class BtAccountSettingScreen extends StatelessWidget {
  const BtAccountSettingScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (context) => BtAccountSettingModel(),
      child: Consumer<BtAccountSettingModel>(builder: (context, model, _) {
        return Scaffold(
          backgroundColor: Colors.white,
          appBar: appBar(context, 'Setting', null),
          body: Container(
            padding: const EdgeInsets.only(left: 32, right: 32),
            child: Column(
              children: [
                Container(
                    width: double.infinity,
                    margin: const EdgeInsets.only(top: 32),
                    padding: const EdgeInsets.only(left: 20, right: 25, top: 12, bottom: 12),
                    decoration: BoxDecoration(
                      color: const Color(0xFFF7F8FA),
                      borderRadius: BorderRadius.circular(12),
                    ),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text("Auto Translate",
                            style: TextStyle(fontSize: 16, color: Color(0xFF404040))),
                        Switch(
                          value: model.switchValue,
                          onChanged: (value) {
                            model.setSwitchValue(value);
                          },
                          activeColor: Colors.blue,
                          inactiveThumbColor: Colors.grey,
                          inactiveTrackColor: Colors.white,
                        ),
                      ],
                    )),
                const SizedBox(height: 20),
                InkWell(
                  child: Container(
                    width: double.infinity,
                    padding: const EdgeInsets.only(left: 20, right: 25, top: 12, bottom: 12),
                    decoration: BoxDecoration(
                      color: const Color(0xFFF7F8FA),
                      borderRadius: BorderRadius.circular(12),
                    ),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text("Delete account",
                            style: TextStyle(fontSize: 16, color: Color(0xFF404040))),
                        Image.asset(
                          'assets/images/bt_icon_arrow_right.png',
                          width: 16,
                          height: 16,
                        ),
                      ],
                    ),
                  ),
                  onTap: () {
                    showSimpleConfirmDialog(context, '', 'Are you sure you want to delete account?', () {
                      EasyLoading.show(status: 'Loading...');
                      model.deleteAccount((success, msg) {
                        if (success) {
                          GetIt.instance<BtAppRouter>().replaceAll([const BtLoginRoute()]);
                        }
                        EasyLoading.showToast(msg);
                      });
                    });
                  },
                ),
                const SizedBox(height: 20),
                InkWell(
                  child: Container(
                    width: double.infinity,
                    padding: const EdgeInsets.only(left: 20, right: 25, top: 12, bottom: 12),
                    decoration: BoxDecoration(
                      color: const Color(0xFFF7F8FA),
                      borderRadius: BorderRadius.circular(12),
                    ),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text("Logout", style: TextStyle(fontSize: 16, color: Color(0xFF404040))),
                        Image.asset(
                          'assets/images/bt_icon_arrow_right.png',
                          width: 16,
                          height: 16,
                        ),
                      ],
                    ),
                  ),
                  onTap: () {
                    showSimpleConfirmDialog(context, '', 'Are you sure you want to log out?', () {
                      EasyLoading.show(status: 'Loading...');
                      model.logout((success, msg) {
                        if (success) {
                          GetIt.instance<BtAppRouter>().replaceAll([const BtLoginRoute()]);
                        }
                        EasyLoading.showToast(msg);
                      });
                    });
                  },
                ),
              ],
            ),
          ),
        );
      }),
    );
  }
}
